package edu.gdkm.sql.dao;

import edu.gdkm.sql.pojo.Orderdetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderdetailMapper {
    // 查询全部订单详情
    @Select("SELECT * FROM orderdetail")
    @Results(id = "orderdetailMap",value = {
            @Result(property = "id", column = "id"),
            @Result(property = "orderid", column = "orderid"),
            @Result(property = "productid", column = "productid"),
            @Result(property = "count", column = "count"),
    })
    List<Orderdetail> findAll();

    // 根据id查询订单详情
    @Select("SELECT * FROM orderdetail WHERE id = #{id}")
    @ResultMap("orderdetailMap")
    Orderdetail findById(int id);

    // 根据订单id查询订单详情
    @Select("SELECT * FROM orderdetail WHERE orderid = #{orderid}")
    @ResultMap("orderdetailMap")
    List<Orderdetail> findByOrderid();

    // 根据商品id查询订单详情
    @Select("SELECT * FROM orderdetail WHERE productid = #{productid}")
    @ResultMap("orderdetailMap")
    List<Orderdetail> findByProductid();

    // 插入订单详情
    @Insert("INSERT INTO orderdetail(orderid, productid, count) VALUES(#{orderid}, #{productid}, #{count})")
    int insertOrderdetail(Orderdetail orderdetail);

    // 更新订单详情
    @Update("UPDATE orderdetail SET orderid=#{orderid}, productid=#{productid}, count=#{count} WHERE id=#{id}")
    @ResultMap("orderdetailMap")
    int updateOrderdetailById(Orderdetail orderdetail);

    // 删除订单详情
    @Delete("DELETE FROM orderdetail WHERE id=#{id}")
    @ResultMap("orderdetailMap")
    int deleteOrderdetailById(int id);
}